{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "a39d6e96",
   "metadata": {},
   "source": [
    "# 本周学习内容\n",
    "> 1.有序的数字结构----字符串(strings)\n",
    "\n",
    "> 2.有序的数字结构----列表(list)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "efa5ebbe",
   "metadata": {},
   "source": [
    "## 1.字符串(strings)\n",
    "> 1.关于字符串的基本内容\n",
    "\n",
    "> 2.关于字符串的方法和函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "82751754",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'span eggs'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'span eggs' "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "43bc4543",
   "metadata": {},
   "source": [
    "### 1.1关于字符串的基本内容"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1dc8a282",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 三引号：保留字符中信息的 格式信息,保留完整的数据信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "12c5ae91",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''doesn't'''"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e1964bde",
   "metadata": {},
   "source": [
    "### 1.2关于字符串的方法和函数\n",
    "\n",
    "\n",
    "> 1.字符串是可以拼接的（属于字符串的运算方式），用 + 进行字符之间的拼接\n",
    "> 2.字符串是有顺序的，从第一个字符开始，从0依次往后，有长度，可以用len()检查字符串的长度\n",
    "> 3.字符串的取值：\n",
    ">> 1.取单个值：从左往右（正数，第一个数是0），从右往左（负数，第一个值是-1）\n",
    ">> 2.取多个值：切片的方法，两个值作为 取值的区间\n",
    "> 4.字符串的方法及函数\n",
    ">> 1.in 查询成员是否存在\n",
    ">> 2.str.count()查询数量\n",
    ">> 3.str.isdigit()判断字符串是否是 数字"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "f7c8ca97",
   "metadata": {},
   "outputs": [],
   "source": [
    "new_name = \"小明\",\"小红\",\"张杰\",\"李华\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "71484c66",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广州南方学院团委欢迎小明\n",
      "广州南方学院团委欢迎小红\n",
      "广州南方学院团委欢迎张杰\n",
      "广州南方学院团委欢迎李华\n"
     ]
    }
   ],
   "source": [
    "for i in new_name:\n",
    "    print(\"广州南方学院团委欢迎\"+i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "7b047095",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院团委欢迎小明'"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"广州南方学院团委欢迎\"+\"小明\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "aaccc766",
   "metadata": {},
   "outputs": [],
   "source": [
    "text = '广州南方学院团委欢迎小明'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "c08f2d76",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "2d596221",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'州'"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "707d40ea",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'南'"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "871551da",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'团委'"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 使用 切片 的方法进行多个值取值\n",
    "text[6:8]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1bafbec2",
   "metadata": {},
   "source": [
    "* str.count()查询数量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "75267ffb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text.count(\"广州\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "13f5851f",
   "metadata": {},
   "source": [
    "* str.isdigit()判断字符串是否是 数字"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "ba20b4ed",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "19 <class 'int'>\n",
      "19 <class 'int'>\n"
     ]
    }
   ],
   "source": [
    "age_li = 19\n",
    "age_wang = 19\n",
    "print(age_li,type(age_li))\n",
    "print(age_wang,type(age_wang))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a7bdce38",
   "metadata": {},
   "source": [
    "## 2.有序的数据结构——列表(list)\n",
    "\n",
    "> 1.列表的基本运算法则（参考：有序的数据结构的运算法则列表）\n",
    "\n",
    "> 2.列表的一般方法（要求：全部掌握，并且做总结在课后）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "df5decca",
   "metadata": {},
   "source": [
    "### 2.1.列表的基本运算法则"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0abc3745",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 思考：假设，有这样一个场景，我要录入/存放一个班的同学的信息（名单信息），用字符串存放是否可行？如何取值呢？\n",
    "#"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "a1f04ba8",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 字符串存放\n",
    "网二_name = '李华,小明,李晓华,小红'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "62201d5a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'李华'"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 字符串取值，比较麻烦\n",
    "网二_name[0:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "943636c0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'小明'"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网二_name[3:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "7506c6a1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'李晓华'"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网二_name[6:9]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "357ac46d",
   "metadata": {},
   "outputs": [],
   "source": [
    "网二_name_list = [\"李华\",\"小明\",\"李晓华\",\"小红\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "7899c65e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'李华'"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网二_name_list[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "f209cf43",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['李晓华', '小红']"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网二_name_list[-2:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "4f66fc7b",
   "metadata": {},
   "outputs": [],
   "source": [
    "网二_age_list = [19,18,19,20]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "1b9d3828",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "19"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网二_age_list[0]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9ada68c9",
   "metadata": {},
   "source": [
    "### 2.2.列表的一般方法\n",
    "\n",
    "> 1.增加\n",
    "> 2.删除\n",
    "> 3.修改\n",
    "> 4.查询in，count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "3df11ce0",
   "metadata": {},
   "outputs": [],
   "source": [
    "names = ['Mike','Merry','Jan','Jack']"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d511cab2",
   "metadata": {},
   "source": [
    "* 学习方法  .tab键\n",
    "\n",
    "> 1.listname.tab键 查看所有方法名称\n",
    "\n",
    "> 2.help(listname.function)查看其中一个方法的具体操作内容"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "5fde08c0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function append:\n",
      "\n",
      "append(object, /) method of builtins.list instance\n",
      "    Append object to the end of the list.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.append)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "715ffa00",
   "metadata": {},
   "outputs": [],
   "source": [
    "names = [\"Mike\",\"Marry\",\"Jan\",\"Jack\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "e7c36487",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.append(\"zhichao\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "4a1e1d6a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Marry', 'Jan', 'Jack', 'zhichao']"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b8c7688d",
   "metadata": {},
   "source": [
    "课后练习——做一个表格，总结列表方法"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
